local zcdiy_yanyu = fk.CreateSkill {
    name = "zcdiy_yanyu",
    tags = { Skill.Compulsory },
}

Fk:loadTranslationTable {
    ["zcdiy_yanyu"] = "燕语",
    [":zcdiy_yanyu"] = "锁定技，游戏开始时，令所有角色获得<a href='yanyu_toskill'>☆燕语</a>；当你因<a href='yanyu_toskill'>☆燕语</a>重铸牌后，你可以分配获得的牌。",

    ["yanyu_toskill"] = "燕语：出牌阶段，你可以重铸【杀】。",
    ["#zcdiy_yanyu-give"] = "燕语：你可以分配这些牌。",

    ["$zcdiy_yanyu1"] = "红袖不解相思意，凭燕传语慰君心！",
    ["$zcdiy_yanyu2"] = "夏燕不羡黄金屋，只栖君家檐下巢！",
}

zcdiy_yanyu:addEffect(fk.GameStart, {
    mute = true,
    can_trigger = function(self, event, target, player)
        return player:hasSkill(zcdiy_yanyu.name)
    end,
    on_use = function(self, event, target, player)
        local room = player.room
        for _, p in ipairs(room:getAlivePlayers()) do
            room:handleAddLoseSkills(p, "yanyu_toskill&", nil, false, true)
        end
    end,
})

zcdiy_yanyu:addEffect(fk.AfterCardsMove, {
    anim_type = "drawcard",
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(zcdiy_yanyu.name) then
            if player:hasSkill(zcdiy_yanyu.name) and
                not player:isNude() then
                for _, move in ipairs(data) do
                    if move.skillName == "yanyu_toskill&" and move.to == player and move.toArea == Card.PlayerHand then
                        for _, info in ipairs(move.moveInfo) do
                            if table.contains(player:getCardIds("h"), info.cardId) then
                                return true
                            end
                        end
                    end
                end
            end
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local ids = {}
        for _, move in ipairs(data) do
            if move.skillName == "yanyu_toskill&" and move.to == player and move.toArea == Card.PlayerHand then
                for _, info in ipairs(move.moveInfo) do
                    if table.contains(player:getCardIds("h"), info.cardId) then
                        table.insertIfNeed(ids, info.cardId)
                    end
                end
            end
        end
        while not player.dead do
            local tos, cards = room:askToChooseCardsAndPlayers(player, {
                min_num = 1,
                max_num = 1,
                min_card_num = 1,
                max_card_num = #ids,
                targets = room.alive_players,
                pattern = tostring(Exppattern { id = ids }),
                skill_name = zcdiy_yanyu.name,
                prompt = "#zcdiy_yanyu-give",
                cancelable = true,
                expand_pile = ids,
            })
            if #tos > 0 and #cards > 0 then
                for _, id in ipairs(cards) do
                    table.removeOne(ids, id)
                end
                room:moveCardTo(cards, Card.PlayerHand, tos[1], fk.ReasonGive, zcdiy_yanyu.name, nil, false, player)
                if #ids == 0 then break end
            else
                room:moveCardTo(ids, Card.PlayerHand, player, fk.ReasonGive, zcdiy_yanyu.name, nil, false, player)
                return
            end
        end
    end,
})
return zcdiy_yanyu
